import sai.mysql.DriverLoading;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class PatientServlet extends HttpServlet
{
PreparedStatement prepare,prepare1;
    @Override
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
	res.setContentType("text/html");
	PrintWriter out = res.getWriter();
	try
	{
	String patientname=req.getParameter("pname");
	String fathername=req.getParameter("fname");
	String dob=req.getParameter("dob");	
	String gender=req.getParameter("gender");		
	String contact=req.getParameter("mobile");  
        out.println(contact);
        String dob1=contact.substring(contact.length()-7, contact.length());	
	String patientid="pat"+dob1;
	out.println(patientid);
        String email=req.getParameter("email");        
	String username=req.getParameter("username");
	String password=req.getParameter("repassword");
	String status=req.getParameter("status");
	String address=req.getParameter("address");
	
	DriverLoading dl = new DriverLoading();
       
        String url="insert into `logindetails` values(?,?,?,?)";
        prepare1=dl.getPreparedStatement(url);
        prepare1.setString(1,username);
        prepare1.setString(2,password);
        prepare1.setString(3,email);
        prepare1.setString(4,"patient");
        prepare1.executeUpdate();
      
	prepare = dl.getPreparedStatement("insert into `patient` values(?,?,?,?,?,?,?,?,?,?,?)");
        prepare.setString(1,patientid);
        prepare.setString(2,username);
        prepare.setString(3,patientname);
        prepare.setString(4,fathername);
        prepare.setString(5,gender);
        prepare.setString(6,dob);
        prepare.setString(7,email);
        prepare.setString(8,status);
        prepare.setString(9,address);
        prepare.setString(10,contact);
        prepare.setString(11,null);
        int x=prepare.executeUpdate();   
        
        if(x!=0)
        {
            out.println("<center><h1>succesfully registered. .</h1>");
        }
	else
        {
          out.println("<center><h1>please try again. .</h1>");  
        }
	}
	catch(Exception e)
	{
	out.println("Exception raised"+e.getMessage());
	}
	
	}
}